package com.wc.alorithm_blue_bridge._排序.Q3994;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;
import java.util.LinkedList;

/**
 * @Author congge
 * @Date 2023/11/5 15:33
 * @description 阿坤老师的独特瓷器
 * https://www.lanqiao.cn/problems/3994/learning/?problem_list_id=22&page=1&sort=students_count
 */
public class Main {
    public static void main(String[] args) {
        Input sc = new Input();
        int n = sc.nextInt();

        LinkedList<Integer> ansMap = new LinkedList<>();
        ansMap.add(0);
        ansMap.add(0);
        int size;
        while (n-- > 0) {
            size = ansMap.size();
            int h = sc.nextInt();
            int w = sc.nextInt();
            for (int i = 0; i < size; i += 2) {
                int curH = ansMap.get(i);
                int curW = ansMap.get(i + 1);
                if (curH < h && curW < w) {
                    ansMap.remove(i);
                    ansMap.remove(i);
                    size -= 2;
                    i -= 2;
                }else if (curH > h && curW > w) {
                    break;
                }
            }
            ansMap.add(h);
            ansMap.add(w);
        }
        System.out.println(ansMap.size() / 2);
    }

    static class Input {
        StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));

        public int nextInt() {
            try {
                in.nextToken();
            } catch (IOException e) {
                e.printStackTrace();
            }

            return (int) in.nval;
        }
    }
}
